package common

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Response struct {
	Code  int         `json:"code"`
	Data  interface{} `json:"data"`
	Error string      `json:"error"`
	Msg   string      `json:"msg"`
}

type PageResult struct {
	List     interface{} `json:"list"`
	Total    int         `json:"total"`
	Page     int         `json:"page"`
	PageSize int         `json:"pageSize"`
}

const (
	ERROR   = 1
	SUCCESS = 0
)

func Result(code int, data interface{}, msg string, err string, c *gin.Context) {
	c.JSON(http.StatusOK, Response{
		code,
		data,
		err,
		msg,
	})
}

func Ok(data interface{}, c *gin.Context) {
	Result(SUCCESS, data, SucceedVal, "", c)
}

func Fail(err string, msg string, c *gin.Context) {
	Result(ERROR, "", msg, err, c)
}
